//
//  TWFXFeedbackViewController.m
//  TWFXWeather
//
//  Created by Lion User on 13-10-21.
//  Copyright (c) 2013年 Lion User. All rights reserved.
//

#import "TWFXFeedbackViewController.h"

@interface TWFXFeedbackViewController ()

@end

// umFeedbackAppKey
static NSString *umFeedbackAppKey = @"5264916356240b87b7152235";


@implementation TWFXFeedbackViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
        self.umFeedback = [UMFeedback sharedInstance];
        [ self.umFeedback setAppkey:umFeedbackAppKey delegate:self];
    }
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    //#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
    if([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
    {
        //边缘延伸的属性.这个属性指定导航栏的四个边缘是否向外延伸？解决导航栏和状态栏重叠的问题
        self.edgesForExtendedLayout = UIRectEdgeNone;
        
        //设置导航栏的样式，默认是白底黑字那个样式，设成title的颜色是白色的那个样式
        [self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];
        
        //设置导航栏的背景色，会影响到状态栏
        [self.navigationController.navigationBar setBarTintColor:[UIColor grayColor]];
        
        
        
        //指定了当Bar使用了不透明图片时，视图是否延伸至Bar所在区域，默认值时NO
        //     self.extendedLayoutIncludesOpaqueBars = NO;
        
        //    self.modalPresentationCapturesStatusBarAppearance = NO;
        
        //设置导航栏是否背景透明?会影响到导航栏里后面被push进来的view里的导航栏是否占用空间
        self.navigationController.navigationBar.translucent = NO;
        
    }
    
    UIBarButtonItem *rightbar = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(feedback)] autorelease];
    
    self.navigationItem.rightBarButtonItem = rightbar;
    self.navigationItem.title = @"关于";
    
    //获取屏幕的高度(不含状态栏)
    CGFloat heightOfScreen = [UIScreen mainScreen].applicationFrame.size.height;

    
    NSString *str1 = @"1、简约天气,最简单的天气,无广告,最省流量.\n\n";
    NSString *str2 = @"2、数据来源于中国天气网,数据准确权威全面,囊括国内2569个县级以上城市.\n\n";
    NSString *str3 = @"3、如有问题,请点右上角进行反馈,我们会及时处理.\n或者邮件联系:245062488@qq.com.\n\n";
    NSString *str4 = @"4、仅以此天气献给亲爱的缎缎~\n\n";
    
    NSString *str = [NSString stringWithFormat:@"%@%@%@%@",str1,str2,str3,str4];
    
    //设置字体,包括字体及其大小
    UIFont *font = [UIFont fontWithName:@"Arial" size:18.0f];
    
    //label可设置的最大高度和宽度
  //  CGSize maxSize = CGSizeMake(300.f, MAXFLOAT);
    
       //字符串在指定区域内按照指定的字体显示时,需要的高度和宽度(宽度在字符串只有一行时有用)
       //一般用法:指定区域的宽度而高度用MAXFLOAT,则返回值包含对应的高度
        //如果指定区域的宽度指定,而字符串要显示的区域的高度超过了指定区域的高度,则高度返回0
      //核心:多行显示,指定宽度,获取高度
    CGSize labelSize = [str sizeWithFont:font  constrainedToSize:CGSizeMake(300.f, heightOfScreen - 44 - 49 - 30) lineBreakMode:NSLineBreakByWordWrapping];
    
    
    self.labelAbout = [[[UILabel alloc] initWithFrame:CGRectMake(10, 30, labelSize.width, labelSize.height)] autorelease];
    self.labelAbout.numberOfLines = 0;
    self.labelAbout.textColor = [UIColor whiteColor];
    self.labelAbout.text = str;
    self.labelAbout.backgroundColor = [UIColor clearColor];
    
    [self.view addSubview:self.labelAbout];
}

-(void) postFinishedWithError:(NSError *)error
{
    if (error == nil) {
        
        NSLog(@"反馈成功");
    }
}


-(void)getFinishedWithError:(NSError *)error
{
    if (error == nil) {
        
        NSLog(@"反馈成功");
    }
}

- (IBAction)btnClick_FeedBack:(id)sender {
    
    [self showNativeFeedbackWithAppkey:umFeedbackAppKey];
   
}


-(void) feedback
{
    [self showNativeFeedbackWithAppkey:umFeedbackAppKey];
}


- (void)showNativeFeedbackWithAppkey:(NSString *)appkey
{
    UMFeedbackViewController *feedbackViewController = [[UMFeedbackViewController alloc] initWithNibName:@"UMFeedbackViewController" bundle:nil];
    feedbackViewController.appkey = appkey;
    
    UIBarButtonItem *backbar = [[[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleBordered target:self action:nil] autorelease];
    self.navigationItem.backBarButtonItem = backbar;
    
    feedbackViewController.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:feedbackViewController animated:YES];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
